import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/afterSales/api/v1';

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询二级服务站索赔预申请'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询二级服务站索赔预申请详情'
});
const approveDesc = formatMessage({
    id: 'api.message.approveDesc',
    defaultMessage: '二级服务站索赔预申请审核'
});
const abandonDesc = formatMessage({
    id: 'api.message.abandonDesc',
    defaultMessage: '二级服务站索赔预申请作废'
});
const partQueryDesc = formatMessage({
    id: 'api.message.partQueryDesc',
    defaultMessage: '查询备件信息'
});
const submitDesc = formatMessage({
    id: 'api.message.submitDesc',
    defaultMessage: '提交二级服务站索赔预申请'
});
const faultModeQueryDesc = formatMessage({
    id: 'api.message.faultModeQueryDesc',
    defaultMessage: '故障原因查询'
});
const getVehicleSoldsDesc = formatMessage({
    id: 'api.message.getVehicleSoldsDesc',
    defaultMessage: '车辆档案查询'
});
const getDutyUnitsDesc = formatMessage({
    id: 'api.message.getDutyUnitsDesc',
    defaultMessage: '责任单位查询'
});
const getDealersDesc = formatMessage({
    id: 'api.message.getDealersDesc',
    defaultMessage: '查询二级服务站信息'
});
const getHistoryListDesc = formatMessage({
    id: 'api.getHistoryListDesc',
    defaultMessage: '查询历史信息'
});

const getHistoryDetailDesc = formatMessage({
    id: 'api.getHistoryDetailDesc',
    defaultMessage: '查询历史详情'
});
const getWarrantyPolicyDesc = formatMessage({
    id: 'api.message.getWarrantyPolicyDesc',
    defaultMessage: '整车索赔政策校验'
});
const getMgmtRatesDesc = formatMessage({
    id: 'api.message.getMgmtRatesDesc',
    defaultMessage: '管理费率查询'
});
const getWorkItemsDesc = formatMessage({
    id: 'api.getWorkItemsDesc',
    defaultMessage: '查询维修项目'
});
const faultItemQueryDesc = formatMessage({
    id: 'api.faultItemQueryDesc',
    defaultMessage: '查询故障代码'
});
const newOrderDesc = formatMessage({
    id: 'api.newOrderDesc',
    defaultMessage: '新增'
});
const modifyOrderDesc = formatMessage({
    id: 'api.modifyOrderDesc',
    defaultMessage: '编辑'
});
const workItemsQueryDesc = formatMessage({
    id: 'api.message.workItemsQueryDesc',
    defaultMessage: '查询维修项目'
});
const getPartServicePricesDesc = formatMessage({
    id: 'api.message.getPartServicePricesDesc',
    defaultMessage: '查询索赔材料价格'
});
const partsQueryDesc = formatMessage({
    id: 'api.message.partsQueryDesc',
    defaultMessage: '查询维修辅料'
});
const newAndSubmitOrderDesc = formatMessage({
    id: 'api.message.newAndSubmitOrderDesc',
    defaultMessage: '新增并提交二级服务站索赔预申请'
});
const modifyAndSubmitOrderDesc = formatMessage({
    id: 'api.message.modifyAndSubmitOrderDesc',
    defaultMessage: '修改并提交二级服务站索赔预申请'
});
const exportDesc = formatMessage({
    id: 'api.message.exportDesc',
    defaultMessage: '导出'
});
const getPartCategoryQuicklyDesc = formatMessage({
    id: 'api.getPartCategoryQuicklyDesc',
    defaultMessage: '查询备件分类'
});
const adjustDesc = formatMessage({
    id: 'api.message.adjustDesc',
    defaultMessage: '二级服务站索赔预申请调整'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/subClaimApply/init`, null, dto.InitDataStruct)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getListDesc));
// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/subClaimApplies/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/subClaimApplies/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
//新增
export const newOrder = data => request(`${baseUrl}/subClaimApplies`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, newOrderDesc));
//修改
export const modifyOrder = (id, data) => request(`${baseUrl}/subClaimApplies/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, modifyOrderDesc));
//新增并提交
export const newAndSubmitOrder = data => request(`${baseUrl}/subClaimApplies/submit`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, newAndSubmitOrderDesc));
//修改并提交
export const modifyAndSubmitOrder = (id, data) => request(`${baseUrl}/subClaimApplies/submit/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, modifyAndSubmitOrderDesc));
//提交
export const submitData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/submit`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, submitDesc));
//审核通过
export const approveData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/pass`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, approveDesc));
//审核通过并生成索赔单
export const approveAndClaimApplyData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/passAndClaimApply`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, approveDesc));
//审核驳回
export const rejectData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/reject`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, approveDesc));
//审核拒赔
export const refuseData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/refuse`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, approveDesc));
//作废
export const abandonData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/abandon`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, abandonDesc));
//故障原因查询
export const faultModeQuery = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/faultModes?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, faultModeQueryDesc));
};
//故障原因快捷查询
export const faultModeQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/faultModes/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, faultModeQueryDesc));
};
//服务站备件查询
export const partQuery = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/parts/forClaim?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, partQueryDesc));
};
// 快捷查询车辆档案
export const getVehicleSoldsQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds/simple?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getVehicleSoldsDesc));
};
// 查询车辆档案
export const getVehicleSolds = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleSolds?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getVehicleSoldsDesc));
};
// 快捷查询责任单位
export const getDutyUnitsQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dutyUnits/base/simple?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDutyUnitsDesc));
};
// 查询责任单位
export const getDutyUnits = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dutyUnits/base?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDutyUnitsDesc));
};
// 快捷查询二级服务站
export const getDealersQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/subDealers/simple?${queryString}`, null, dto.DealerSimpleList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealersDesc));
};
// 查询二级服务站
export const getDealers = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/subDealers?${queryString}`, null, dto.DealerList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealersDesc));
};
// 查询服务站国家币种
export const getCurrencyCountryName = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/dealers/forServiceInformation?${queryString}`, null, dto.DealerList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDealersDesc));
};
//历史查询
export const getHistoryList = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/subClaimApplyHistories/forCurrentUser?${queryString}`, null, dto.HistoryList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getHistoryListDesc));
};
//历史查询详情
export const getHistoryDetail = id => request(`${baseUrl}/subClaimApplyHistories/${id}`, null, dto.HistoryDetail)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, getHistoryDetailDesc));

//查询故障代码
export const faultItemQuery = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/faultItems?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, faultItemQueryDesc));
};
//故障代码快捷查询
export const faultItemQuickly = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/faultItems/simple?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, faultItemQueryDesc));
};
//历史查询
export const getSubClaimHistoriesList = condition => {
    const queryString = stringify(condition);
    return request(`${baseUrl}/subClaims/forSubClaimHistory?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getHistoryListDesc));
};
//政策校验
export const getWarrantyPolicy = data => request(`${baseUrl}/warrantyPolicies/forClaim`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.query, getWarrantyPolicyDesc));
//管理费率
export const getMgmtRates = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/mgmtRates?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getMgmtRatesDesc));
};
//查询万能工时
export const getWorkItems = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/workItems/forClaim?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getWorkItemsDesc));
};
//查询维修项目
export const workItemsQuery = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/workItems/query?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, workItemsQueryDesc));
};
//索赔材料价格查询
export const getPartServicePrices = data => request(`${baseUrl}/partServicePrices/forClaim`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.query, getPartServicePricesDesc));

//查询辅料
export const partAssistQuery = data => request(`${baseUrl}/parts/query`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, partsQueryDesc));
// 导出
export const queryExport = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/subClaimApplies/export/forCurrentUser?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, exportDesc))
        .then(res => res.data);
};

//历史附件下载
export const getHistoryDownload = data => {
    const queryString = stringify(data);
    return request(`${baseUrl}/files/ftpIsDownload?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, null));
};
// 查询备件分类
export const getPartCategory = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partCategories?${queryString}`, null, dto.SelectList)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getPartCategoryQuicklyDesc));
};
//调整
export const adjustData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/adjust`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, adjustDesc));
//调整并生成索赔单
export const adjustAndClaimApplyData = (id, data) => request(`${baseUrl}/subClaimApplies/${id}/adjustAndClaimApply`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, adjustDesc));

import {productCategoryType} from '../Enum';

const productCategoryQueryDesc = formatMessage({
    id: 'api.message.productCategoryQueryDesc',
    defaultMessage: '查询车型信息'
});
export const productCategoryQuery = () =>
    request(`${baseUrl}/productCategories?type=${productCategoryType.车型}&isAll=true`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, productCategoryQueryDesc));
